package main

import (
	_ "smart_home/routers"
	"github.com/astaxie/beego"
	"github.com/beego/i18n"
	m "smart_home/models"
	"github.com/astaxie/beego/orm"
	_"github.com/go-sql-driver/mysql"
	//"github.com/astaxie/beego/logs"
	//"fmt"
)
func init() {
	orm.RegisterDriver("mysql", orm.DR_MySQL)

	orm.RegisterDataBase("default", "mysql", "root:xujianhua@/smart_home?charset=utf8")
}

func addAdmin(){

	permision,_:=beego.AppConfig.Int("admin_permission")
	admin := m.Admin{Tel:beego.AppConfig.String("admin_tel"),UserName:beego.AppConfig.String("admin_name"),UserPw:beego.AppConfig.String("admin_pw"),FamilyMemID:beego.AppConfig.String("admin_family_memID"),Permission:permision}
	m.AddAdmin(&admin)
}
func addTestUser(){
	user := m.User{Tel:"15928972923",UserName:"xujianhua"}
	m.AddUser(&user)
}
func main() {
	beego.AdminHttpAddr = "localhost"
	beego.AdminHttpPort = 8088
	beego.EnableAdmin = true
	beego.SetLogger("file", `{"filename":"smart_home.log"}`)
	beego.SetLogFuncCall(true)
	addAdmin()
	addTestUser()
	beego.Info("system start\n")
	orm.RunCommand()
    beego.AddFuncMap("i18n", i18n.Tr)
	beego.Run()

}

